package com.hq.ims.data.utils;

import com.hq.web.utils.RedisUtils;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.concurrent.TimeUnit;

/**
 * @email 526666031@qq.com
 * @detail RedisConstant
 */
public class StringRedisUtils {

    /**
     * 是否存在
     *
     * @param redisKey 标识
     */
    public static Boolean redisKeyIsExists(String redisKey) {
        String v = getStringRedis().opsForValue().get(redisKey);
        return v != null;
    }

    /**
     * 保存
     *
     * @param redisKey 标识
     * @param v        值
     * @param minutes  分钟
     */
    public static void saveRedisKey(String redisKey, String v, long minutes) {
        getStringRedis().opsForValue().set(redisKey, v, minutes, TimeUnit.MINUTES);
    }

    /**
     * 保存
     *
     * @param redisKey 标识
     */
    public static String getRedisKey(String redisKey) {
        return getStringRedis().opsForValue().get(redisKey);
    }

    public static boolean delRedisKey(String redisKey) {
        return getStringRedis().delete(redisKey);
    }


    public static RedisTemplate<String, String> getStringRedis() {
        RedisTemplate<String, String> redisTemplate = RedisUtils.getRedisTemplate(RedisUtils.STRING_REDIS_TEMPLATE_KEY);
        return redisTemplate;
    }

}
